﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './pointsdetails.scss'
import cat04 from '../../assets/kedouimg01/sckf.png'
import xl from '../../assets/kedouimg01/xl.png'
import goto from '../mall/images/goto01.png'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
		resdata:[],
		result:[],
		pageNumber:0,
		money:0,
		totalWdt:0,
		lockUpWdt:0,
		lockUpWdtFormula:0,
		platformLockUpWdt:0,
		navindex:1,
		islisyr:0,
		createDateEnd:'',
		appmark:CommonJs.getmark(),
    }
  }
  config = {
    navigationBarTitleText: '加载中'
  }
  componentWillMount () {
	if(this.state.appmark=='xjzb'){
		Taro.setNavigationBarTitle({title:'WDT'})
	}
	else{
		Taro.setNavigationBarTitle({title:'勋章'})
	}
	var money =this.$router.preload.money;
	var totalWdt =this.$router.preload.totalWdt;
	var lockUpWdt =this.$router.preload.lockUpWdt;
	var lockUpWdtFormula =this.$router.preload.lockUpWdtFormula;
	var platformLockUpWdt =this.$router.preload.platformLockUpWdt;
	this.setState({
		money:money,
		totalWdt:totalWdt,
		lockUpWdt:lockUpWdt,
		lockUpWdtFormula:lockUpWdtFormula,
		platformLockUpWdt:platformLockUpWdt,
	  })
	this.getalldate()
	this.getdate(0)
  }
  componentDidShow () {
  	
  }
	
	getalldate(){
		var _this = this;
		var url = '/crm/papi/v1.9/currency?assetType=WDT'
		CommonJs.ajaxRequest(url,'','GET',function(res){
			if (res.data.length>0) {
				var resdata = _this.state.resdata
				resdata = res.data[0]
				  _this.setState({
					resdata: resdata,
				  })     
			  } 
			},"wfw")
	}

  getdate(pageNumber){
    var _this=this
 	if(_this.state.createDateEnd != ''){
 	 	var url = '/crm/papi/v1.9/currency?assetType=WDT'+ '&createDateEnd=' + _this.state.createDateEnd
 	 }else{
 	 	var url = '/crm/papi/v1.9/currency?assetType=WDT'
 	 }
    var dates={}
    var type=this.state.navindex;
    if(type==1){
  	  dates.inOrOut=true
    }
    else{
  	  dates.inOrOut=false
	}
	
    CommonJs.ajaxRequest(url,dates,'GET',function(res){
  	if (res.data.length>0) {
		  var results = _this.state.result  
		  var result = res.data[0].assetTypeDetailsList
		  if(pageNumber==0){
			results=[]
		  }
  		for(var i = 0; i < result.length; i++){
  		  results.push(result[i]);
  		}
  		  _this.setState({
			  result: results,
			  pageNumber:1
  		  })     
  	  } 
  	},"wfw")
  }     
  changeMoney(val){
  	var _this=this;
  	_this.setState({
  		  result:[],
		  navindex:val,   
		  pageNumber:0 
  	})
  	setTimeout(function(){
  		_this.getdate(0)
  	},600)	     
  }
  opendetails(url){
      this.$preload({
        regType:7
      })
      CommonJs.openTo(url)
	}
	onDateChange(e){
		var _this = this;
	  var createDateEnd = _this.state.createDateEnd
	  var evalue = e.detail.value
		  createDateEnd =evalue
		  _this.setState({
			  result:[],
			  createDateEnd:createDateEnd,
			  islisyr:1
			  
			})
		setTimeout(function(){
			_this.getdate(0)
		},600)
	}

  render () {
	const result = this.state.result
	const resdata = this.state.resdata
	const money = this.state.money
	const appmark = this.state.appmark
    return (
      <View className='page'>
    		<ScrollView className='wdt-list' scrollY='true' onScrollToLower={this.loadMore.bind(this,'')}>

       			<View className='wdt-tj' style={appmark=='xjzb'?'':'display:none'}>
       				<View className='wdt-li'>
						<View className='wdt-top'>锁仓WDT={this.state.lockUpWdtFormula}</View>
						   <Text>WDT释放/WDT锁仓</Text>
						<View className='wdt-lis'>
							<Picker mode='date' onChange={this.onDateChange.bind(this)} fields='month'>
                			  <View className='picker'>{this.state.islisyr == 1 ?this.state.createDateEnd : '本月'}<Image className='xl' mode='widthFix' src={xl}></Image></View>
              				</Picker>
						</View>
					 </View>
					<View className='wdt-li02'>{money/100}/{lockUpWdt/100}</View>
       				<View className='wdt-li03'>
						<Text className='wdt-r'>总锁仓：{this.state.platformLockUpWdt/100}</Text>
       					<Text className='wdt-l'>总释放：{this.state.totalWdt/100}</Text>
       				</View>
       			</View>

				   <View className='wdt-tj' style={appmark=='xjzb'?'display:none':''}>
       				<View className='wdt-li'>
						<View className='wdt-top'>勋章={this.state.lockUpWdtFormula}</View>
						   <Text>勋章</Text>
						<View className='wdt-lis'>
							<Picker mode='date' onChange={this.onDateChange.bind(this)} fields='month'>
                			  <View className='picker'>{this.state.islisyr == 1 ?this.state.createDateEnd : '本月'}<Image className='xl' mode='widthFix' src={xl}></Image></View>
              				</Picker>
						</View>
					 </View>
					<View className='wdt-li02'>{money/100}/{lockUpWdt/100}</View>
       				<View className='wdt-li03'>
						<Text className='wdt-r'>总勋章：{this.state.platformLockUpWdt/100}</Text>
       					<Text className='wdt-l'>总释放：{this.state.totalWdt/100}</Text>
       				</View>
       			</View>

				   <View className='gxh-oterh'>
	       			<View className='goods-order' onClick={this.opendetails.bind(this,'/pages/my/zrcapital')}>
	       				<Text className=''>转让WDT</Text>
						<Image className="goto" mode="widthFix" src={goto}></Image>
			        </View>
			      </View>

       			<View className='wdt-mx'>
       				<View className='wdt-tit'>
       					<Text className={this.state.navindex==1?'tit-li activer':'tit-li'} onClick={this.changeMoney.bind(this,1)}>收入</Text>
       					<Text className={this.state.navindex==2?'tit-li activer':'tit-li'} onClick={this.changeMoney.bind(this,2)}>支出</Text>
       				</View>
       				
       				<View className='qun-mingxibo'>
					   <View className='nodate' style={!result||result.length==0?'':'display:none;'}>暂无数据</View>
						   {result.map((item,index)=>(
	       				<View className='qun-mingxilist'>
			              <View className='qun-mngxicont'>
			                <View className='qun-mngxileft'>
			                  <Text className='qun-minxizngs qun-reanao'>{item.note}</Text>
			                  <Text className='qun-minxizngs qun-minxitit'>{CommonJs.FormatDate(item.createAt,3)}</Text>
			                </View>
			                <View className='qun-mngxiright'>
			                  <Text style="margin-top:0" className={this.state.navindex==1?'qun-minxizngs qun-minxijine':'qun-minxizngs qun-minxijine qun-colors'}>{item.changeAmount/100}</Text>
			                </View>
			              </View>
			          </View>
					  ))}
			        </View>
       			</View>
       	</ScrollView>
      </View>
    )
  }
}

 